<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../../set.jsp" />
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>管理员平台</title>
<jsp:include page="../../cite.jsp" />
<link rel="stylesheet" href="${_path}/theme/theme-menu.css">
<script src="${_path}/lib/bootbox-4.4.0/bootbox.min.js"></script>
<script src="${_path}/lib/loong/loong-repopover.js"></script>
<style>
.body {
	padding-top: 40px;
}

.body .popover>.popover-content {
	color: #000;
	font-size: 12px;
}

.body .table td {
	vertical-align: middle;
	word-break: break-all;
	word-wrap: break-word;
}

.modal#modal .modal-body>pre {
	line-height: 20px;
	overflow-x: hidden;
}
</style>
</head>
<body>
	<jsp:include page="../../header.jsp" />
	<jsp:include page="./manage-menu.jsp?active=errors" />
	<div class="body">
		<div class="panel panel-default">
			<div class="panel-body">
				<a class="btn btn-default btn-sm pull-right" href=" ./" title="重置" data-toggle="tooltip">
					<i class="fa fa-refresh"></i>
				</a>
				<c:forEach var="type" items="${types}">
					<a class="btn btn-default btn-sm" href="?type=${type}">${type}</a>
				</c:forEach>
			</div>
		</div>
		<div class="panel panel-default">
			<div class="panel-body">
				<table class="table table-hover text-center" id="table">
					<caption>
						异常列表
						<c:if test="${param.type != null}">
							${param.type}
							<button type="button" class="btn btn-success btn-xs pull-right" value="${param.type}" id="remove">
								<i class="fa fa-minus"></i>
							</button>
						</c:if>
					</caption>
					<thead>
						<tr>
							<td width="180">
								<strong>调用时间</strong>
							</td>
							<td width="150">
								<strong>IP</strong>
							</td>
							<td>
								<strong>访问路径</strong>
							</td>
							<td width="150">
								<strong>详情</strong>
							</td>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="row" items="${type_detail.rows}">
							<tr>
								<td>${row.time}</td>
								<td>${row.ip}</td>
								<td>
									<c:if test="${row.url != null}">
										<c:choose>
											<c:when test="${row.param == null}">
												<a href="${row.url}" target="_blank">${row.url}</a>
											</c:when>
											<c:otherwise>
												<a href="${row.url}?${row.param}" target="_blank">${row.url}?${row.param}</a>
											</c:otherwise>
										</c:choose>
									</c:if>
								</td>
								<td>
									<c:if test="${row.message != null}">
										<a class="btn btn-default btn-sm row-detail" href="javascript:;">查看</a>
										<div class="hide message">${row.message}</div>
									</c:if>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
				<div class="text-center">
					<jsp:include page="../../pager.jsp?${pageContext.request.queryString}">
						<jsp:param name="page" value="${type_detail.page.getPage()}" />
						<jsp:param name="size" value="${type_detail.page.getSize()}" />
						<jsp:param name="total" value="${type_detail.page.getTotal()}" />
					</jsp:include>
				</div>
			</div>
		</div>
	</div>
	<div class="modal fade" id="modal">
		<div class="modal-dialog modal-lg">
			<div class="modal-content">
				<div class="modal-header">
					<a class="close" data-dismiss="modal" href="javascript:;">
						<i class="fa fa-close"></i>
					</a>
					<span>
						<strong>${param.type}</strong>
					</span>
				</div>
				<div class="modal-body">
					<pre></pre>
				</div>
			</div>
		</div>
	</div>
	<script>
		$(function() {
			bootbox.setLocale('zh_CN');
			$('#table td>.row-detail').bind('click', function() {
				var detail = $(this).next().text();
				$('#modal pre').text(detail);
				$('#modal').modal('show');
			});
			$('#remove').repopover('再次点击，清空', function(n) {
				clear(n.attr('value'));
			});
			function clear(type) {
				$.ajax({
					url : './remove/',
					type : 'post',
					dataType : 'json',
					data : {
						type : type
					},
					success : function(result) {
						if (result.succ == 0)
							location.href = './';
						else
							bootbox.alert(result.message);
					},
					error : function() {
						bootbox.alert('网络连接失败');
						console.log('清空错误类型失败');
					}
				});
			}
		});
	</script>
</body>
</html>